package com.choichumgming.rentcat.web.rpc;

import com.choichumgming.rentcat.common.api.CommonResult;
import com.choichumgming.rentcat.dto.MemberDetails;
import com.choichumgming.rentcat.model.UmsMember;
import com.choichumgming.rentcat.service.UmsMemberFeignApi;
import com.choichumgming.rentcat.service.UmsMemberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@Api(tags = "UmsMemberFeignClient", description = "会员服务feign")
@RestController
@RequestMapping("/api")
public class UmsMemberFeignClient implements UmsMemberFeignApi {
    @Autowired
    private UmsMemberService memberService;

    @Override
    @ApiOperation(value = "根据userId获得用户")
    @RequestMapping(value = "/user/item")
    @ResponseBody
    public CommonResult<UmsMember> getByUserId(@RequestParam("userId") Long userId) {
        UmsMember umsMember = memberService.getById(userId);
        return  CommonResult.success(umsMember);
    }
    /**
     * 根据username获取用户
     *
     */
    @Override
    @ApiOperation(value = "根据username获得用户")
    @RequestMapping(value = "/loadUserByUsername")
    @ResponseBody
    public CommonResult<MemberDetails> loadUserByUsername(@RequestParam("username") String username) {
        MemberDetails umsUmsDetails = memberService.loadUserByUsername(username);
        return  CommonResult.success(umsUmsDetails);
    }


}
